$(function(){
    var userInfo = JSON.parse(localStorage.getItem("userInfo"));
    var openId = localStorage.getItem("openId");
    if(userInfo.name == '' || userInfo.name ==null){
        $(".no").text(' ');
    }else{
        $(".no").text('您已领取了该红包，不能再领取了！');
    }
    // if(openId){
    //     getNewhb(openId);
    // }
    getNewhb(openId);
});
function getNewhb(openId){
    $.ajax({
        type: "GET",
        url: baseUrl + "/rest/lkHongbaoController/list/"+openId,
        contentType:"application/json;charset=UTF-8",
        dataType: "json",
        data:{
            pageNumber:'1',
            pageSize:'100'
        },
        success: function(e){
            if(e.ok){
                console.log(e);
                if(e.data.length){
                    let a = '';
                    for(let i=0;i<e.data.length;i++){
                        a += '<div class="item">';
                        a += '<div class="l">';
                        a += '<div class="price">￥'+e.data[i].hb04+'</div>';
                        a += '<div class="txt">抵用券</div>';
                        a += '</div>';
                        a += '<div class="c">';
                        a += '<p class="tit">'+e.data[i].hb06+'</p>';
                        a += '<p class="info">仅限手机号：'+e.data[i].hb02+'</p>';
                        a += '</div>';
                        a += '<div class="r">';
                        a += '<div class="btn" data-id="'+e.data[i].id+'">立即领取</div>';
                        a += '</div>';
                        a += '</div>';
                    }
                    $(".wrap").html(' ').append(a);
                    // 立即领取
                    $(".btn").click(function(){
                        $(this).text('已经领取')
                        var id = $(this).attr('data-id');
                        console.log(id);
                        messageBox('领取成功！')
                    });
                }
            }
        }
    });
}